  <?php

  $con = mysqli_connect("localhost", "root", "root");
  if (!$con) {
     die('Could not connect: '.mysqli_error());
  }
  
  mysqli_select_db($con,"alignedvisions");
  if (isset($_POST['submit'])) {
    $username = $_POST["username"];
    $password = $_POST["password"];
    
    $sql1="SELECT classification FROM login WHERE username = '$username' AND password = '$password'";
    $result = mysqli_query($con, $sql1);
  
    if (!$result){
       die ('ERROR: '. mysqli_error($con));
    }
    $classification = "";
    while($row = mysqli_fetch_array($result))
    {
        $classification = $row['classification'];
        
    } 
    $nameUser = "";
    $step="";
    if (strcmp($classification,"e") == 0){
        $sql2="SELECT firstName FROM entrepreneurForm WHERE username = '$username'";
        $result= mysqli_query($con,"SELECT week FROM entrepreneurForm WHERE login='$username'");
        //$step = mysqli_query($con, "SELECT step FROM entrepreneurform WHERE username = '$username'" );
    }
    if (strcmp($classification,"i") == 0){
        $sql2="SELECT firstName FROM studentForm WHERE username = '$username'";
        $result= mysqli_query($con,"SELECT week FROM studentForm WHERE login='$username'");
       
    }
    if (strcmp($classification,"c") == 0){
        $sql2="SELECT firstName FROM consultantForm WHERE username = '$username'";
        $result= mysqli_query($con,"SELECT week FROM consultantForm WHERE login='$username'");
       
    }
    $nameUser = mysqli_query($con, $sql2);
    
    
    if (!$result){
       die ('ERROR: '. mysqli_error($con));
    }
  
    $week= $result->fetch_object()->week;
    
  } 
  mysqli_close($con);
 
 
 ?>    

<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" type="text/css" href="weekProcess.css"/>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Aligned Visions</title>
    </head>
    <body>
        <div id="all">
            <div id='boxInside'>
            <?php
            
            $nameUser=$username;
            if (strcmp($classification,"e") == 0 || strcmp($classification,"i") == 0 || strcmp($classification,"c") == 0 || strcmp($classification,"adm") == 0 ){   
                echo "<h2>Hello <b>".$username." </b></h2><br> Click next to start your week process: ";
                echo " <a href='initialPage.php?user=$nameUser&week=week$week&classification=$classification'> Next </a> ";
            }
            if (strcmp($classification,"") == 0){
                ?>
                    <h1>I'm sorry! It was not possible to connect.</h1>
                    <h1>Please verify your username/password and try again.</h1>
                    <input type="button" value="GO BACK" onclick="location.href='index.php';" />
                <?php
            }
            ?>
            </div>        
        </div>    
    </body>
</html>    